package main

import (
	"container/list"
	"fmt"
)

func main() {
	l := list.New()
	PrintList(l)
	// 返回当前插入元素
	front := l.PushFront(1)
	PrintList(l)
	// 返回当前插入元素
	back := l.PushBack(3)
	PrintList(l)
	pushFront := l.PushFront(11)
	PrintList(l)
	pushBack := l.PushBack(33)
	PrintList(l)
	// MoveAfter() 移动指定元素到另一个指定元素的后面
	l.MoveAfter(front, pushBack)
	PrintList(l)
	// MoveBefore() 移动指定元素到另一个指定元素的前面
	l.MoveBefore(back, pushFront)
	PrintList(l)
}

func PrintList(l *list.List)  {
	if l == nil || l.Len() == 0 {
		fmt.Println("不存在元素值")
		return
	}
	for front := l.Front(); front != nil; front = front.Next() {
		fmt.Print(front.Value, " ")
	}
	fmt.Println()
}